<template>
  <div class="table-header">
    <el-button type="primary" @click="emits('addClick')">
      <i class="iconfont icon-tianjia"></i> {{ btnText }}</el-button
    >
    <div v-if="showSearch">
      <el-input
        style="width: 300px"
        v-model.trim="val"
        :placeholder="placeholderText"
        clearable
      >
        <template #append>
          <el-button type="info" plain @click="emits('clickSearch')">
            <i class="iconfont icon-sousuo"></i>
            搜索</el-button
          >
        </template>
      </el-input>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { computed } from 'vue'
const props = withDefaults(
  defineProps<{
    btnText: string
    searchValue: string
    placeholderText?: string
    showSearch?: boolean
  }>(),
  {
    placeholderText: '请输入',
    showSearch: false
  }
)
const emits = defineEmits<{
  (e: 'update:searchValue', newVal: string): void
  (e: 'clickSearch'): void
  (e: 'addClick'): void
}>()
const val = computed({
  get() {
    return props.searchValue
  },
  set(newVal) {
    emits('update:searchValue', newVal)
  }
})
</script>

<style lang="scss" scoped>
.table-header {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
</style>
